package com.wframe.project.former.web.floor;

import com.frame.database.JdataBean;
import com.frame.pageform.DataPageForm;
import com.frame.pageform.annotation.Login;
import com.wframe.project.former.dataservices.floor.UiFloorDao;
import com.wframe.project.former.dataservices.floor.UiFloorPanelService;
import com.wframe.project.former.dataservices.floor.UiFloorService;
import com.wframe.project.jnd.entity.UiFloor;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by Administrator on 2017/5/25.
 */
@Login
public class UiFloorPage extends DataPageForm {

    private static UiFloorService uiFloorService = UiFloorService.getIntance();
    private static UiFloorPanelService uiFloorPanelService = UiFloorPanelService.getIntance();
    private JdataBean bean;

    @Override
    public String execute() throws Exception {
        // TODO Auto-generated method stub
        setPagination(uiFloorService.queryUiFloor(bean, getPageSize_(), getPageNum()));
        return "/webadmin/floor/uiFloorList.jsp";
    }

    @Override
    public String show() throws Exception {
        // TODO Auto-generated method stub
        bean=uiFloorService.getBean(bean.getString("id"));
        return "/webadmin/floor/uifloorEdit.jsp";
    }

    @Override
    public String toDel() throws Exception {
        return getJsonObject().toString();
    }

    //修改楼层
    @Override
    public boolean toUpdate() throws Exception {
        // TODO Auto-generated method stub
        if(StringUtils.isNotBlank(bean.getString("id"))){
            Map key=new HashMap();
            key.put("id", bean.getString("id"));
            uiFloorService.update(bean.getDataMap(),key);
            getJsonObject().getJsonPage().showOkMsg("修改成功");
        }else {
            bean.put("create_time", new Date());
            uiFloorService.save(bean.getDataMap());
        }
        getJsonObject().getJsonPage().closeWin("ok");
        return false;
    }

    //批量更新状态
    public String updatestatus() throws Exception {
        if (getPrimaryKey_() != null) {
            for (String id : getPrimaryKey_()) {
                uiFloorService.upDateUiFloorStatus(id,bean.getString("state"));
            }
        }
        return getJsonObject().toString();
    }

    //进入添加页面
    public String uiFloorAdd(){
        return "/webadmin/floor/uiFloorAdd.jsp";
    }

    public JdataBean getBean() {
        return bean;
    }

    public void setBean(JdataBean bean) {
        this.bean = bean;
    }
}
